﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.OS
{
    /// <summary>
    /// 注册表
    /// </summary>
    public class Regedit
    {
        public static object GetRegistryValue(string path, string paramName)
        {
            object value = null;
#if !NETSTANDARD2_0
            RegistryKey root = Registry.LocalMachine;
            RegistryKey rk = root.OpenSubKey(path);
            if (rk != null)
            {
                value = rk.GetValue(paramName, null);
            }
#endif
            return value;
        }

        public static void SetRegistryValue(string path, string paramName, object value)
        {
#if !NETSTANDARD2_0
            //1.向注册表中写信息
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@path, true))
            {
                if (key == null)
                {
                    using (RegistryKey myKey = Registry.LocalMachine.CreateSubKey(@path))
                    {
                        myKey.SetValue(paramName, value);
                    }
                }
                else
                {
                    key.SetValue(paramName, value);
                }
            }
#endif
        }
    }
}
